home *** CD-ROM | disk | FTP | other *** search
- Path: nntp-xfer-2.csn.net!yuma!steffend
- From: steffend@lamar.colostate.edu (Dave Steffen)
- Newsgroups: comp.lang.c++
- Subject: Re: random number in C++
- Date: 31 Jan 1996 23:12:32 GMT
- Organization: Colorado State University, Fort Collins, CO 80523
- Message-ID: <4eot10$380a@yuma.ACNS.ColoState.EDU>
- References: <4eoh03$6jb@pacemaker.cts>
- NNTP-Posting-Host: glitch.physics.colostate.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- Brian A. Bucher (babucher@mtu.edu) wrote:
-
- > Is there _ANY_ way to get a truly random number in a C++ program?
- > rand and srand do not generate random numbers, they generate
- > pseudo-random numbers, which is what I don't need.
-
- > Thanks,
- > Boo
-
- Well, OK, no there isn't any way to generate _truly_ random
- numbers in _any_ language. A computer is a deterministic system (at
- least in theory ;-) and therefore can not generate a truly random
- sequence of numbers without special hardware input (white noise,
- geiger counter, etc.)
-
- So from this point of view, the answer to your question is no,
- it's not possible to get a truly random number sequence... in ANY
- language.
-
- However, what you _can_ get from a computer is a "good"
- sequence of pseudo-random numbers, "good" meaning
- "non-correlated". When people talk about random number generators,
- what they really mean is a "pseudo-random number generator with no
- statistical correlations in its output".
-
- The problem is that most "system-supplied" random number
- generators are, in fact, _NOT_ good random number generators; their
- output is correlated. If you're serious about needing a good stream of
- randoms, check out "Numerical Recipies in C, 2nd Ed" for an excellent
- discussion of what's wrong with most implementations of the rand() and
- srand() functions, and some good alternative routines. I personally
- use a C++ified version of their ran1() routine; some of the experts
- tell me that some "cryptography" routines are even better.
-
- /\
- \/
-
- Dave Steffen No, his mind is not for rent
- Dept. of Physics To any God or Government
- Colorado State University Always hopeful, yet discontent
- steffend@lamar.colostate edu He knows changes aren't permanent-
- But change is...
- "Speak softly...
- ... and carry a black belt!" -Neal Peart / RUSH
- -----------------------------------------------------------------------
-